package svl;

import java.io.IOException;
import java.net.InetAddress;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Delegado.BD;



/**
 * Servlet implementation class listaPrecios
 */
@WebServlet("/Remitos")
public class Remitos extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * Default constructor.
	 */
	public Remitos() {
		// TODO Auto-generated constructor stub
	}
	

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		BD delegado = new BD();
		delegado.LookupService(InetAddress.getLocalHost().getHostAddress());		
		
		int cantidad = delegado.generarRemitos();
		
		request.setAttribute("cantidad", cantidad);
		
		System.out.println("Cantidad de remitos generados: " + cantidad);
		
		request.setAttribute("mensaje", "Se generaron " + cantidad + " de remitos correspondientes a las ordenes de pedido pendientes.");
		
		String dire = "/jsp/Remitos.jsp";
		RequestDispatcher dispatcher = request.getRequestDispatcher(dire);
	    dispatcher.forward(request, response);
		
	}
}
